package org.gen.config;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @author 朱良才
 * @Email zhuliangcai@itcast.com
 * @Date 2017-10-16
 */
public abstract class GenConfig {

    private static Properties prop = new Properties();
    static {
        InputStream inputStream = GenConfig.class.getResourceAsStream("/properties/config.properties");
        try {
            prop.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("can not find config file /properties/config.properties");
        }
    }

    public static String getJdbcurl() {
        return prop.getProperty("jdbc.url");
    }

    public static String getDriverClassName() {
        return prop.getProperty("jdbc.driver");
    }

    public static String getUsername() {
        return  prop.getProperty("jdbc.username");
    }

    public static String getPassword() {
        return prop.getProperty("jdbc.password");
    }

    public static String getPackageName() {
        return prop.getProperty("packageName");
    }

    public static String getMapperPackageName() {
        return prop.getProperty("mapperPackageName");
    }

    public static String getMappertestPackageName() {
        return prop.getProperty("mappertestPackageName");
    }


    public static String getAuthor() {
        return prop.getProperty("author");
    }

    public static String getEmail() {
        return prop.getProperty("email");
    }

    public static Map configPersonal() {
        Map<String, Object> root = new HashMap<String, Object>();
        root.put("packageName", GenConfig.getPackageName());
        root.put("mapperPackageName", GenConfig.getMapperPackageName());
        root.put("mappertestPackageName", GenConfig.getMappertestPackageName());
        root.put("author", GenConfig.getAuthor());
        root.put("email", GenConfig.getEmail());
        root.put("date", new Date());
        return root;
    }

}
